//
//  MyViewController.m
//  TravelEveryDay
//
//  Created by 路洪宇 on 15/10/19.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "MyViewController.h"
#import "Play_LocationTableViewCell.h"
#import "MyCollectionViewController.h"
#import "ParallaxHeaderView.h"
#import "MyHeaderView.h"
@interface MyViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic, strong)MyHeaderView *headerView;
@property(nonatomic, strong)NSArray *imageArray;
@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _choseArr = @[@"我的收藏",@"清除缓存",@"夜间模式",@"关于我们"];
     self.imageArray = @[@"me_favourite@2x.png",@"me_history@2x.png",@"me_setting@2x.png",@"me_draft@2x.png"];
    self.view.backgroundColor =[UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    [[self navigationController] setNavigationBarHidden:YES animated:NO];
    [self setUpTableView];
    
     self.headerView = [[MyHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, (SCREEN_HEIGHT-50)/2)];
    UIImageView *userFace = [[UIImageView alloc] initWithFrame:CGRectMake(self.headerView.frame.size.width/2-45, self.headerView.frame.size.height/2-100, 90, 90)];
    [userFace setImage:[UIImage imageNamed:@"play-user.jpg"]];
    userFace.layer.cornerRadius = 45;
    userFace.layer.masksToBounds = YES;
    [self.headerView addSubview:userFace];
    
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, userFace.frame.size.height+userFace.frame.origin.y+10, SCREEN_WIDTH, 30)];
    [nameLabel setText:@"Pineapple"];
    [nameLabel setTextAlignment:NSTextAlignmentCenter];
    [nameLabel setTextColor:[UIColor grayColor]];
    [nameLabel setFont:[UIFont systemFontOfSize:16.]];
    [self.headerView addSubview:nameLabel];
    
    UIImageView *trophyImage = [[UIImageView alloc] initWithFrame:CGRectMake(userFace.frame.origin.x+12, nameLabel.frame.size.height+nameLabel.frame.origin.y+5, 15,15)];
    [trophyImage setImage:[UIImage imageNamed:@"play-jiangbei.png"]];
    [self.headerView addSubview:trophyImage];
    
    UILabel *levelLabe = [[UILabel alloc] initWithFrame:CGRectMake(trophyImage.frame.size.width+trophyImage.frame.origin.x, trophyImage.frame.origin.y, 50, 20)];
    [levelLabe setText:@" Level 1"];
    [levelLabe setTextAlignment:NSTextAlignmentLeft];
    [levelLabe setTextColor:[UIColor lightGrayColor]];
    [levelLabe setFont:[UIFont systemFontOfSize:13.]];
    [self.headerView addSubview:levelLabe];
    
//    UIButton *likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [likeButton setFrame:CGRectMake(SCREEN_WIDTH/2-80, self.headerView.frame.size.height-40, 50, 30)];
//    [likeButton setTitle:@"喜欢" forState:UIControlStateNormal];
//    likeButton.titleLabel.font = [UIFont systemFontOfSize:16.];
//    [likeButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//    [self.headerView addSubview:likeButton];
   
    [self.myTableView setTableHeaderView:self.headerView];
}

-(void)setUpTableView
{
    _myTableView  = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _myTableView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    _myTableView.delegate = self;
    _myTableView.tableFooterView = [[UIView alloc] init];
   [_myTableView setSeparatorColor:[UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1]];
    _myTableView.dataSource = self;
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 400)];
    _myTableView.tableFooterView = footerView;
    
    UILabel *copyrightLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-100, 20, 200, 20)];
    [copyrightLabel setText:[NSString stringWithFormat:@"面包iPhone版"]];
    [copyrightLabel setTextAlignment:NSTextAlignmentCenter];
    copyrightLabel.font = [UIFont systemFontOfSize:13.];
    copyrightLabel.textColor = [UIColor lightGrayColor];
    [footerView addSubview:copyrightLabel];
    
      UILabel *bbLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-100, copyrightLabel.frame.size.height+20, 200, 20)];
    [bbLabel setText:[NSString stringWithFormat:@"版本1.0"]];
    [bbLabel setTextAlignment:NSTextAlignmentCenter];
    bbLabel.font = [UIFont systemFontOfSize:13.];
    bbLabel.textColor = [UIColor lightGrayColor];
    [footerView addSubview:bbLabel];
    
      UILabel *coLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-100, bbLabel.frame.size.height+bbLabel.frame.origin.y, 200, 20)];
    [coLabel setText:[NSString stringWithFormat:@"Copyright©2015 LCW.inc"]];
    [coLabel setTextAlignment:NSTextAlignmentCenter];
    coLabel.font = [UIFont systemFontOfSize:13.];
    coLabel.textColor = [UIColor lightGrayColor];
    [footerView addSubview:coLabel];
    [self.view addSubview:_myTableView];
}

#pragma mark- TableView Delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _choseArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellId = @"UITableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
    }
    cell.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = [_choseArr objectAtIndex:indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:15.];
    cell.textLabel.textColor = [UIColor lightGrayColor];
    cell.imageView.frame = CGRectMake(0, 0, 20, 20);
    cell.imageView.image = [UIImage imageNamed:[_imageArray objectAtIndex:indexPath.row]];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            NSLog(@"我的收藏");
            MyCollectionViewController *collectionVC = [[MyCollectionViewController alloc] init];
            [self.navigationController pushViewController:collectionVC animated:YES];
        }
            break;
        case 1:
        {
            NSLog(@"清除缓存");

        }
            break;
        case 2:
            NSLog(@"夜间模式");
            break;
        case 3:
            NSLog(@"关于我们");
            break;
        default:
            break;
    }
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [self.headerView updateHeaderView:scrollView.contentOffset];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
